package member

import (
	"github.com/gin-gonic/gin"
	"go-papers/models"
	"go-papers/tools"
	"go-papers/tools/app"
)

func ShareOrgan(c *gin.Context) {
	var data models.Order
	var err error
	var pageSize = 10
	var pageIndex = 1

	if size := c.Request.FormValue("pageSize"); size != "" {
		pageSize = tools.StrToInt(err, size)
	}
	if index := c.Request.FormValue("pageIndex"); index != "" {
		pageIndex = tools.StrToInt(err, index)
	}

	data.ShareUserId = tools.GetMemberId(c) // @TODO 当前登录的用户uid
	if data.ShareUserId == 0 {
		data.ShareUserId = -1 // 微信端
	}
	data.ShareType = "2"

	data.OrderNo = c.Request.FormValue("orderNo")
	data.OrderName = c.Request.FormValue("orderName")
	data.BrandName = c.Request.FormValue("brandName")
	data.OrganName = c.Request.FormValue("organName")
	data.CourseName = c.Request.FormValue("courseName")
	data.OrderStatus = c.Request.FormValue("orderStatus")
	data.MemberPhone = c.Request.FormValue("memberPhone")
	data.MemberName = c.Request.FormValue("memberName")
	data.MemberMomName = c.Request.FormValue("memberMomName")
	data.PayType = c.Request.FormValue("payType")
	data.PayNo = c.Request.FormValue("payNo")
	data.PayTime = c.Request.FormValue("payTime")
	data.ShareStatus = c.Request.FormValue("shareStatus")

	data.AddressSearch = c.Request.FormValue("addressSearch") //所在地区
	data.Address = c.Request.FormValue("address")             //小区名称
	data.OrganName = c.Request.FormValue("organName")         //机构名称
	data.BrandName = c.Request.FormValue("brandName")         //品牌名称

	data.PayTimeStart = c.Request.FormValue("payTimeStart")
	data.PayTimeEnd = c.Request.FormValue("payTimeEnd")

	data.ShareTimeMonth = c.Request.FormValue("shareTimeMonth")
	if data.ShareTimeMonth == "" {
		data.ShareTimeMonth = c.Query("shareTimeMonth")
	}

	result, count, err := data.GetGatewaySharePage(pageSize, pageIndex) // ShareOrgan 2
	if err != nil {
		app.ApiResp(c, -1, "数据操作失败："+err.Error(), nil)
		return
	}

	app.PageOK(c, result, count, pageIndex, pageSize, "")
}

func ShareCourse(c *gin.Context) {
	var data models.Order
	var err error
	var pageSize = 10
	var pageIndex = 1

	if size := c.Request.FormValue("pageSize"); size != "" {
		pageSize = tools.StrToInt(err, size)
	}
	if index := c.Request.FormValue("pageIndex"); index != "" {
		pageIndex = tools.StrToInt(err, index)
	}

	data.ShareUserId = tools.GetMemberId(c) // @TODO 当前登录的用户uid
	if data.ShareUserId == 0 {
		data.ShareUserId = -1 //微信端
	}
	data.ShareType = "3"

	data.OrderNo = c.Request.FormValue("orderNo")
	data.OrderName = c.Request.FormValue("orderName")
	data.BrandName = c.Request.FormValue("brandName")
	data.OrganName = c.Request.FormValue("organName")
	data.CourseName = c.Request.FormValue("courseName")
	data.OrderStatus = c.Request.FormValue("orderStatus")
	data.MemberPhone = c.Request.FormValue("memberPhone")
	data.MemberName = c.Request.FormValue("memberName")
	data.MemberMomName = c.Request.FormValue("memberMomName")
	data.PayType = c.Request.FormValue("payType")
	data.PayNo = c.Request.FormValue("payNo")
	data.PayTime = c.Request.FormValue("payTime")
	data.ShareStatus = c.Request.FormValue("shareStatus")

	data.AddressSearch = c.Request.FormValue("addressSearch") //所在地区
	data.Address = c.Request.FormValue("address")             //小区名称
	data.OrganName = c.Request.FormValue("organName")         //机构名称
	data.BrandName = c.Request.FormValue("brandName")         //品牌名称

	data.PayTimeStart = c.Request.FormValue("payTimeStart")
	data.PayTimeEnd = c.Request.FormValue("payTimeEnd")

	data.ShareTimeMonth = c.Request.FormValue("shareTimeMonth")
	if data.ShareTimeMonth == "" {
		data.ShareTimeMonth = c.Query("shareTimeMonth")
	}
	result, count, err := data.GetGatewaySharePage(pageSize, pageIndex) // ShareCourse 2
	if err != nil {
		app.ApiResp(c, -1, "数据操作失败："+err.Error(), nil)
		return
	}

	app.PageOK(c, result, count, pageIndex, pageSize, "")
}
